package com.longge;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

public class ThirdMax {


    public int thirdMax(int[] nums) {
        ArrayList<Integer> sortNums = new ArrayList<>();
        for (int num : nums) {
            sortNums.add(num);
        }
        List<Integer> sortLists = sortNums.stream().distinct().sorted(Comparator.comparing(Integer::intValue).reversed()).collect(Collectors.toList());
        if (sortLists.size() >= 3) return sortLists.get(2);
        else return sortLists.get(0);
    }
}
